package cn.yunhe.biz;

import cn.yunhe.bean.Page;
import cn.yunhe.bean.Scenery;
import cn.yunhe.bean.Ticket;
import cn.yunhe.dao.SceneryMapper;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;


import java.util.List;

public class SceneryService {
    SqlSession session = SqlSessionFactoryUtil.getSqlSession();
    SceneryMapper sceneryMapper = session.getMapper(SceneryMapper.class);

    public  List<Scenery> getAllScenery(){
        return sceneryMapper.getAllScenery();
    }

    public List<String> GetKeywordName(String keyword){
        return sceneryMapper.GetKeywordName(keyword);
    }

    public List<Scenery> getSceneryByPage(Page page) {
        return sceneryMapper.getSceneryByPage(page);
    }

    public int getSceneryCount(){
        return sceneryMapper.getSceneryCount();
    }

    public Scenery getAllByName(int sceId){
        return sceneryMapper.getAllByName(sceId);
    }

    public List<Ticket> getTicketByuserid(String userid){
        return sceneryMapper.getTicketByuserid(userid);
    }

    public  int getScenerySum(){
        return sceneryMapper.getScenerySum();
    }

    public List<Scenery> getSceneryByKeyWord(String keyWord){
        return sceneryMapper.getSceneryByKeyWrod(keyWord);
    }

    /**
     * 得到所有推荐的景点信息展示在主页轮播图上
     * @return
     */
    public  List<Scenery> getAllRecommendScenery(){
        return sceneryMapper.getAllRecommendScenery();
    }
    /**
     * 通过景点id获得单个景点的信息
     * @param sceId
     * @return
     */
    public  Scenery getSceneryById(Integer sceId){
        return sceneryMapper.getSceneryById(sceId);
    }

    public  List<Scenery> getSceneryByRecommend(Integer recommend){
        return sceneryMapper.getSceneryByRecommend(recommend);
    }
    public  List<Scenery> getPopularityIndex(){
        return sceneryMapper.getPopularityIndex();
    }

    /**
     * 由后台将景点添加到数据库
     * @param scenery
     * @return
     */
    public  int addScenery(Scenery scenery){
        int result = sceneryMapper.addScenery(scenery);
        if(result>0){
            session.commit();
        }
        return result;
    }

    public int getIdByName(String name){
               System.out.println(name);
              return sceneryMapper.getIdByName(name);
    }



}
